package com.freight.user.controller;

import com.freight.core.common.utils.PageUtil;
import com.freight.core.common.utils.ResultUtil;
import com.freight.core.common.utils.SecurityUtil;
import com.freight.core.common.vo.PageVo;
import com.freight.core.common.vo.Result;
import com.freight.core.common.vo.SearchVo;
import com.freight.core.entity.User;
import com.freight.user.entity.CompanyUser;
import com.freight.user.service.CompanyUserService;
import com.freight.user.vo.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;
import java.util.Map;

/**
 * @author huyingtai
 */
@Slf4j
@RestController
@Api(description = "货主信息管理接口")
@RequestMapping("/freight/companyUser")
@Transactional
public class UserCompanyController   {

    @Autowired
    private CompanyUserService companyUserService;

    @Autowired
    private SecurityUtil securityUtil;


    @RequestMapping(value = "/homePageStatistics", method = RequestMethod.POST)
    @ApiOperation(value = "货主端 --- 首页统计")
    public Result<HomePageStatisticsVo> homePageStatistics() {
        HomePageStatisticsVo homePageStatisticsVo=companyUserService.homePageStatistics();
        return new ResultUtil<HomePageStatisticsVo>().setData(homePageStatisticsVo);
    }

    @RequestMapping(value = "/getCommpanyInformation", method = RequestMethod.POST)
    @ApiOperation(value = "根据用户id获取货主信息")
    public Result<CommpanyInformationVo> getCommpanyInformation(Long userId) {
        CommpanyInformationVo commpanyInformationVo = companyUserService.getCommpanyInformation(userId);
        return new ResultUtil<CommpanyInformationVo>().setData(commpanyInformationVo);
    }

    @RequestMapping(value = "/getByCondition", method = RequestMethod.GET)
    @ApiOperation(value = "多条件分页获取")
    public Result<Page<CompanyUser>> getByCondition(CompanyUser companyUser, SearchVo searchVo, PageVo pageVo) {

        Page<CompanyUser> page = companyUserService.findByCondition(companyUser, searchVo, PageUtil.initPage(pageVo));
        return new ResultUtil<Page<CompanyUser>>().setData(page);
    }

    @RequestMapping(value = "/getCompanyState", method = RequestMethod.GET)
    @ApiOperation(value = "货主状态")
    public Result<Integer> getCompanyState() {
        User u = securityUtil.getCurrUser();
        Integer res = companyUserService.getCompanyState(u.getId());
        return new ResultUtil<Integer>().setData(res);
    }

    @RequestMapping(value = "/getCompanyPicId", method = RequestMethod.GET)
    @ApiOperation(value = "获取货主所有的图片")
    public Result<CompanyAllPicId> getCompanyPicId(Long userId) {

        CompanyAllPicId res = companyUserService.getCompanyPicId(userId);
        return new ResultUtil<CompanyAllPicId>().setData(res);
    }

}
